package com.wyl.mine.setting

import android.view.View
import com.lzg.extend.BaseResponse
import com.lzg.extend.JsonConvert
import com.lzg.extend.toDisposables
import com.lzy.okgo.OkGo
import com.lzy.okrx2.adapter.ObservableBody
import com.wuhenzhizao.titlebar.widget.CommonTitleBar
import com.wyl.base.ACacheHelper
import com.wyl.base.MINE_ABOUT_US
import com.wyl.base.MINE_FEEDBACK
import com.wyl.libbase.base.NormalActivity
import com.wyl.libbase.extend.toast
import com.wyl.mine.R
import kotlinx.android.synthetic.main.about_us_activity.titlebar
import kotlinx.android.synthetic.main.feedback_activity.*

class FeedbackActivity : NormalActivity() {
    override fun getLayoutId(): Int = R.layout.feedback_activity

    override fun initView() {
        titlebar.setListener { _, action, _ ->
            when (action) {
                CommonTitleBar.ACTION_LEFT_BUTTON -> onBackPressed()
                else -> {
                }
            }
        }
    }

    override fun loadData() {

    }

    override fun onClick(v: View) {
        val content = edit.text.toString()
        // 提交
        if (content.length < 6) {
            toast("内容不能少于6个字")
            return
        }
        OkGo.post<BaseResponse<Map<String, String>>>(MINE_FEEDBACK)
            .params("appUserId", ACacheHelper.id)
            .params("content", content)
            .converter(object : JsonConvert<BaseResponse<Map<String, String>>>() {})
            .adapt(ObservableBody<BaseResponse<Map<String, String>>>())
            .subscribe({
                toast("谢谢您的反馈")
                onBackPressed()
            }, {
                onError(it)
                it.printStackTrace()
            }).toDisposables(disposables)
    }
}
